#![allow(unused)]
pub mod common;
pub mod error;

use std::str::FromStr;

use common::{BlockchainType, ChainInfo, Network};

pub const APPROVE_GAS_READY: u128 = 5_000_000_000;
pub const APPROVE_LIMIT: u128 = 100_000_000_000_000_000_000;

pub fn get_client_url(chain: &str, env: &str) -> &'static str {
    let network = match env {
        "DEV" => Network::Testnet,
        "TEST" => Network::Testnet,
        "PROD" => Network::Mainnet,
        _ => Network::Mainnet,
    };
    let chain_info = BlockchainType::from_str(chain)
        .and_then(|bc_type| ChainInfo::from_type(bc_type, network))
        .unwrap();
    chain_info.client_url
}

#[cfg(test)]
mod tests {
    use std::str::FromStr;

    use common::{BlockchainType, ChainInfo};

    use super::*;

    #[test]
    fn it_works() {
        let bsc_ret = BlockchainType::from_str("BSC")
            .and_then(|blockchain_type| {
                ChainInfo::from_type(blockchain_type, common::Network::Mainnet)
            })
            .unwrap();
        let sol_ret = BlockchainType::from_str("SOL")
            .and_then(|blockchain_type| {
                ChainInfo::from_type(blockchain_type, common::Network::Mainnet)
            })
            .unwrap();

        println!("Binance: {:?}", bsc_ret);
        println!("Solana: {:?}", sol_ret);
    }
}
